package com.jy.modules.cims.auxiliary.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.sysUtils.SimpleStringUtils;
import com.jy.modules.cims.component.common.DictDeatil;
import com.jy.modules.cims.data.dao.CreditSettleBillDao;
import com.jy.modules.cims.data.dto.CreditSettleBillDto;

@Service("com.jy.modules.cims.auxiliary.service.CreditSettleBillService")
public class CreditSettleBillService {
	@Autowired
	private DictDeatil dict;
	
	 @Autowired
	 private CreditSettleBillDao creditSettleBillDao;

	public List<CreditSettleBillDto> searchCreditSettleBillDtoByPaging(Map<String, Object> searchParams){
		return creditSettleBillDao.searchCreditSettleBillDtoByPaging(searchParams);
	}
	public List<CreditSettleBillDto> getCreditSettleBillSum(Map<String, Object> searchParams){
		return 	creditSettleBillDao.getCreditSettleBillDtoSum(searchParams);
	}

	public List<CreditSettleBillDto> exportCreditSettleBillDtoList(Map<String, Object> searchParams) throws Exception {
		
		List<CreditSettleBillDto> dataList = creditSettleBillDao.exportCreditSettleBillDtoList(searchParams);
		String[] columnCodes = new String[] { "creditorStatus", "cooperorgCodes", "abnormalSettle", "plan_status", "monthRepayPsType", "CREDIT_SOURCE" };

		Map<String, Map> excelColumnsConvertMap = dict.queryDictDetailByTempalteMap(columnCodes);

		List<CreditSettleBillDto> listDto = new ArrayList<CreditSettleBillDto>();
		Object value = "";
		for (CreditSettleBillDto creditSettleBill : dataList) {
			if (SimpleStringUtils.hasText(creditSettleBill.getCooperorgCode())) {
				value = excelColumnsConvertMap.get("cooperorgCodes").get(creditSettleBill.getCooperorgCode());
				creditSettleBill.setCooperorgName(value == null ? creditSettleBill.getCooperorgCode() : value.toString());// 合作机构
			}
			if (SimpleStringUtils.hasText(creditSettleBill.getCreditorStatus())) {
				value = excelColumnsConvertMap.get("creditorStatus").get(creditSettleBill.getCreditorStatus());
				creditSettleBill.setCreditorStatus(value == null ? creditSettleBill.getCreditorStatus() : value.toString());// 债权状态
			}
			if (SimpleStringUtils.hasText(creditSettleBill.getCreditSource())) {
				value = excelColumnsConvertMap.get("CREDIT_SOURCE").get(creditSettleBill.getCreditSource());
				creditSettleBill.setCreditSource(value == null ? creditSettleBill.getCreditSource() : value.toString());// 债权来源
			}
			if (SimpleStringUtils.hasText(creditSettleBill.getReplaceType())) {
				value = excelColumnsConvertMap.get("monthRepayPsType").get(creditSettleBill.getReplaceType());
				creditSettleBill.setReplaceType(value == null ? creditSettleBill.getReplaceType() : value.toString());// 月还处理方式
			}
			if (SimpleStringUtils.hasText(creditSettleBill.getSettlementSign())) {
				value = excelColumnsConvertMap.get("plan_status").get(creditSettleBill.getSettlementSign());
				creditSettleBill.setSettlementSignName(value == null ? creditSettleBill.getSettlementSign() : value.toString());// 结算状态
			}
			if (SimpleStringUtils.hasText(creditSettleBill.getAbnormalSettle())) {
				value = excelColumnsConvertMap.get("abnormalSettle").get(creditSettleBill.getAbnormalSettle());
				creditSettleBill.setAbnormalSettle(value == null ? creditSettleBill.getAbnormalSettle() : value.toString());// 异常状态
			}else{
				creditSettleBill.setBizDate(null);
			}

			listDto.add(creditSettleBill);
		}
		return listDto;
	}	
}
